﻿using System;
using System.Collections;

namespace UniRx.Operators
{
	// Token: 0x02000360 RID: 864
	internal abstract class NthZipObserverBase<T> : OperatorObserverBase<T, T>, IZipObservable
	{
		// Token: 0x060011B4 RID: 4532 RVA: 0x0005034C File Offset: 0x0004E74C
		public NthZipObserverBase(IObserver<T> observer, IDisposable cancel) : base(observer, cancel)
		{
		}

		// Token: 0x060011B5 RID: 4533 RVA: 0x00050356 File Offset: 0x0004E756
		protected void SetQueue(ICollection[] queues)
		{
			this.queues = queues;
			this.length = queues.Length;
			this.isDone = new bool[this.length];
		}

		// Token: 0x060011B6 RID: 4534
		public abstract T GetResult();

		// Token: 0x060011B7 RID: 4535 RVA: 0x0005037C File Offset: 0x0004E77C
		public void Dequeue(int index)
		{
			bool flag = true;
			for (int i = 0; i < this.length; i++)
			{
				if (this.queues[i].Count == 0)
				{
					flag = false;
					break;
				}
			}
			if (flag)
			{
				T value = default(T);
				try
				{
					value = this.GetResult();
				}
				catch (Exception error)
				{
					try
					{
						this.observer.OnError(error);
					}
					finally
					{
						base.Dispose();
					}
					return;
				}
				this.OnNext(value);
				return;
			}
			bool flag2 = true;
			for (int j = 0; j < this.length; j++)
			{
				if (j != index)
				{
					if (!this.isDone[j])
					{
						flag2 = false;
						break;
					}
				}
			}
			if (flag2)
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
				return;
			}
		}

		// Token: 0x060011B8 RID: 4536 RVA: 0x00050488 File Offset: 0x0004E888
		public void Done(int index)
		{
			this.isDone[index] = true;
			bool flag = true;
			for (int i = 0; i < this.length; i++)
			{
				if (!this.isDone[i])
				{
					flag = false;
					break;
				}
			}
			if (flag)
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}
		}

		// Token: 0x060011B9 RID: 4537 RVA: 0x000504FC File Offset: 0x0004E8FC
		public void Fail(Exception error)
		{
			try
			{
				this.observer.OnError(error);
			}
			finally
			{
				base.Dispose();
			}
		}

		// Token: 0x04000A90 RID: 2704
		private ICollection[] queues;

		// Token: 0x04000A91 RID: 2705
		private bool[] isDone;

		// Token: 0x04000A92 RID: 2706
		private int length;
	}
}
